package weaver.interfaces.jjy.duss.util;

import com.sap.mw.jco.IFunctionTemplate;
import com.sap.mw.jco.IRepository;
import com.sap.mw.jco.JCO;

import java.util.HashMap;
import java.util.Map;
import java.util.Properties;


public class SAPConnPool03 {

	public static  void getSAPPoolConnection() {
		JCO.PoolManager clientPoolManager  = JCO.getClientPoolManager();
		try {
			String sapclient = "800";           //要登录的客户端
			String userid = "HR_CON_ADM";       //用户名
			String password = "SAP@s4dev";      //登录口令
			String hostname = "192.168.200.11"; //系统的IP地址
			String systemnumber = "00";         //系统编号
			String Language = "ZH";             //系统语言
			String group = "S4P";
			String r3name = "S4P";
			String mshost = "192.168.200.11";
			JCO.Pool pool = clientPoolManager.getPool("Pool");
			if (pool == null) {
				Properties logonProperties = new Properties();
				logonProperties.put("jco.client.ashost",  hostname);
				logonProperties.put("jco.client.client", sapclient);
				logonProperties.put("jco.client.sysnr", systemnumber);
				logonProperties.put("jco.client.user", userid);
				logonProperties.put("jco.client.passwd", password);
				logonProperties.put("jco.client.lang", Language);
				logonProperties.put("jco.client.mshost", mshost);
				logonProperties.put("jco.client.r3name", r3name);
				logonProperties.put("jco.client.group", group);
				JCO.addClientPool("Pool",150,logonProperties);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	public static void querySalesOrderGetlist(){
		JCO.Client client = null;
		getSAPPoolConnection();
		IRepository iRepository = JCO.createRepository("iRepository","Pool");
		IFunctionTemplate ft = iRepository.getFunctionTemplate("ZFM_HR_PERNR");
		JCO.Function funGetList = ft.getFunction();
		JCO.ParameterList input = funGetList.getImportParameterList();
		input.setValue("SEL","JIEKNO");
		client = JCO.getClient("Pool");
		client.execute(funGetList);
		JCO.Table t0 = funGetList.getTableParameterList().getTable("PT0185");
			t0.appendRow();//追加行
			t0.setValue("01", "ICTYP");
			t0.setValue("522126199408174519", "ICNUM");
		JCO.ParameterList  out = funGetList.getExportParameterList();//输出参数和结构处理
		JCO.ParameterList  Table00 = funGetList.getTableParameterList();//输出表的处理

		//返回处理结果以及日志
		Map<String,String> resultMap = new HashMap<String,String>();
		String[] tabs={"PT0185"};
		String[] str={"PS0000","PS0001","PS0002"};
		resultMap = SAPComMehtod.SAPreturn(out,Table00);
		System.out.println(resultMap.toString());

	}

	public static void main(String[] args) {
		querySalesOrderGetlist();
	}

}
